package com.atguigu.gulimallseckill.controller;

import com.atguigu.common.to.seckill.RedisSeckillTo;
import com.atguigu.common.utils.R;
import com.atguigu.gulimallseckill.service.SeckillService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.*;

@RestController
public class SeckillController {
    @Autowired
    SeckillService seckillService;
    /**
     * 获取秒杀的商品
     * @return
     */
    @GetMapping("/currentSeckillSkus")
    public R getCurrentSeckillSkus(){
       List<RedisSeckillTo> data = seckillService.getSeckillSkus();
       return R.ok().put("data",data);
    }
    @GetMapping("/sku/seckill/{skuId}")
    public R getSkuSeckillInfo(@PathVariable("skuId") Long skuId){
        RedisSeckillTo data = seckillService.getSeckillSkuInfo(skuId);
        return R.ok().put("data",data);
    }
    @GetMapping("/kill")
    public R kill(@RequestParam("killId") String killId, @RequestParam("key") String key,@RequestParam("num")Integer num){
        //校验合法性
        String orderSn = seckillService.kill(killId,key,num);
        return R.ok().put("data",orderSn);
    }
}
